<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="javax.jdo.Query" %>
<%@ page import="java.util.List" %>
<%@ page import="member.*" %>
<%@ page import="shared.PMF" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>會員資料</title>
</head>
<body>

<h2><font color=blue>請注意！當資料刪除之後不能回復！</font></h2>

<%

PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = pm.newQuery(Member.class);

if(request.getParameterValues("chkbox")!=null){
	String chkbox[]=request.getParameterValues("chkbox");
	int length=java.lang.reflect.Array.getLength(chkbox);
	for(int i=0;i<length;i++)
	{
		out.println();
		List<Member> results = (List<Member>) query.execute();
		if (!results.isEmpty()) {
			for (Member p : results) {
				if(String.valueOf(p.getId()).equals(chkbox[i])){
					out.print("<font color=red>"+chkbox[i]+" "+p.getName());
					pm.deletePersistent(p);
					out.println(" 成功刪除!"+"</font><br>");
				}//if
			}//for
		}//if
		
	}//for
}
%>

<form id="form1" name="form1" method="get" action="/mem/stockMes.jsp">
<table border="1">

<%

query.setFilter("transTimes >= 0");
//query.setOrdering("hireDate desc");
//query.declareParameters("String lastNameParam");

try {
    List<Member> results = (List<Member>) query.execute();
    if (!results.isEmpty()) {
%>
<tr><td></td><td>會員編號</td><td>會員姓名</td><td>會員暱稱</td><td>會員評分</td><td>交易次數</td><td>交易點數量</td><td>提供/需求</td>
<%
        for (Member p : results) {
%>
<tr>
<td><input type="checkbox" name="chkbox" value="<%=p.getId() %>" /></td>
<td><%=p.getId() %></td>
<td><%=p.getName() %></td>
<td><%=p.getNickName() %></td>
<td><%=p.getScore() %></td>
<td><%=p.getTransTimes() %></td>
<td><%=p.getPoint() %></td>
<td><%=p.getRequirement() %></td>
</tr>
<% 
        }// for
    } else {
    	out.println("無會員資料!");
    }
} finally {
    query.closeAll();
    pm.close();
}
%>
</table>
<input type="submit" value="刪除" />
</form>
<a href="index_un.jsp">回到首頁</a>
</body>
</html>